<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con">
            <span>编辑业绩</span><div class="move_title"></div><?php include "../public/sub.php";?></div>
    </div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">年份</label>
                        <div class="layui-input-block">
                            <input type="text" name="year" id="year" placeholder="请选择" clearable autocomplete="off" class="layui-input bdate_y">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目类型</label>
                        <div class="layui-input-block">
                            <div id="type"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目业主</label>
                        <div class="layui-input-block">
                            <input type="text" name="jian_unit" id="jian_unit" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>合同金额(万元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="money" id="money" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput6">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目所在地</label>
                        <div class="layui-input-block" style="z-index: 1;">
                            <input type="text" name="addr" id="addr" placeholder="请选择" readonly clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">开工时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="start_dt" id="start_dt" placeholder="请输入" clearable autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">竣工时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="end_dt" id="end_dt" placeholder="请选择" clearable autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">项目说明</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目经理</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="jingcert" class="layui-input jingcert" onclick="openPage('../public/choose_cert.php?dom=jingcert&page=achieve','80%','80%')">
                            <div class="choose_div" id="jingcert" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_cert.php?dom=jingcert&page=achieve','80%','80%')">
                                <i class="layui-icon layui-icon-search"></i>
                            </span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">技术负责人</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="shucert" class="layui-input shucert" onclick="openPage('../public/choose_cert.php?dom=shucert&page=achieve','80%','80%')">
                            <div class="choose_div" id="shucert" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_cert.php?dom=shucert&page=achieve','80%','80%')">
                                <i class="layui-icon layui-icon-search"></i>
                            </span>
                        </div>
                    </div>
                </div>
            </div>

            <?php include 'upinfo.php'?>
        </div>


    </div>
</form>
<script>
    var param_id = getQueryVariable('id');


    $("#commentForm").validate({
        rules: {
            name: {required: true},
            money: {required: true},
        },
        messages:{
            name: {required: "请输入"},
            money: {required: "请输入"},
        }
    });


    layui.use(['laytp','form'], function() {
        var form = layui.form;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_achieve_edit,data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;
                $('#year').val(data.year);
                $('#name').val(data.name);
                $('#addr').val(data.addr);
                $('#money').val(data.money);
                $('#start_dt').val(data.start_dt);
                $('#end_dt').val(data.end_dt);
                $('#explain').val(data.explain);
                $('#jian_unit').val(data.jian_unit);

                if(data.jingcert_info){
                    set_choose_btn('jingcert',data.jingcert_info.id,data.jingcert_info.personname+'('+data.jingcert_info.name+')');
                }
                if(data.shucert_info){
                    set_choose_btn('shucert',data.shucert_info.id,data.shucert_info.personname+'('+data.shucert_info.name+')');
                }

                load_areas('addr', res.data.addr, 3);

                xmselect_dan('type', res.data.type, data.type, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#type").find('xm-select').removeClass('error');
                    }else{
                        $("#type").find('xm-select').addClass('error');
                    }
                });



                initParseMoney();
                public_upload_file_load('files_zb',data.files_zb);
                public_upload_file_load('files_jg',data.files_jg);
                public_upload_file_load('files_sg',data.files_sg);
                public_upload_file_load('files_fp',data.files_fp);
                public_upload_file_load('files_hd',data.files_hd);
                public_upload_file_load('files_qt',data.files_qt);
                render_from();
            }
        });

        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();

            data.field.jingcert = get_choose_val('jingcert');
            data.field.shucert = get_choose_val('shucert');

            if(!data.field.type){
                $("#type").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#type").find('xm-select').removeClass('error');
            }

            if(!validRes){ return false; }


            parseMoney(data);
            data.field.files_zb = public_upload_file_value('files_zb');
            data.field.files_jg = public_upload_file_value('files_jg');
            data.field.files_sg = public_upload_file_value('files_sg');
            data.field.files_fp = public_upload_file_value('files_fp');
            data.field.files_hd = public_upload_file_value('files_hd');
            data.field.files_qt = public_upload_file_value('files_qt');
            data.field.id = param_id;
            facade.ajax({url: ask_achieve_edit, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });
</script>
</body>
</html>
